<!-- eslint-disable vue/no-unused-vars -->
<template>
	<Maximize v-if="themeConfig.maximize" />
	<div v-if="route1.path != '/iot/home'">
		<Breadcrumb id="breadcrumb" v-if="themeConfig.breadcrumb" />
		<Tabs v-else />
	</div>
	<el-main :class="layoutClass">
		<!-- 使用动态组件，点击菜单无法加载到页面 -->
		<router-view v-slot="{ Component, route }">
			<!-- <transition appear name="fade-transform" mode="out-in"> -->
			<keep-alive :include="keepAliveStore.keepAliveName">
				<component :is="Component" :key="route.fullPath" v-if="isRouterShow" />
			</keep-alive>
			<!-- </transition> -->
		</router-view>
	</el-main>
	<el-footer v-if="themeConfig.footer">
		<Footer />
	</el-footer>
</template>

<script setup lang="ts">
import { ref, computed, onBeforeUnmount, provide } from "vue";
import { GlobalStore } from "@/stores";
import { KeepAliveStore } from "@/stores/modules/keepAlive";
import Maximize from "./components/Maximize.vue";
import Tabs from "@/layouts/components/Tabs/index.vue";
import Footer from "@/layouts/components/Footer/index.vue";
import Breadcrumb from "./../Header/components/Breadcrumb.vue";
import { useRouter, useRoute } from "vue-router";
const globalStore = GlobalStore();
const keepAliveStore = KeepAliveStore();
const themeConfig = computed(() => globalStore.themeConfig);
const isCollapse = computed(() => globalStore.themeConfig.isCollapse);
const route1 = useRoute();
const router = useRouter();
const layoutClass = ref("");
watch(
	() => router.currentRoute.value.path,
	() => {
		//要执行的方法
		const query = router.currentRoute;
		layoutClass.value = (query.value.meta.perms as any)?.layout;
	},
	{ immediate: true, deep: true }
);

// 刷新当前页面
const isRouterShow = ref(true);
const refreshCurrentPage = (val: boolean) => {
	isRouterShow.value = val;
};
provide("refresh", refreshCurrentPage);

// 监听窗口大小变化，折叠侧边栏
const screenWidth = ref<number>(0);
const listeningWindow = () => {
	screenWidth.value = document.body.clientWidth;
	if (!isCollapse.value && screenWidth.value < 1200) globalStore.setThemeConfig({ ...themeConfig.value, isCollapse: true });
	if (isCollapse.value && screenWidth.value > 1200) globalStore.setThemeConfig({ ...themeConfig.value, isCollapse: false });
};
window.addEventListener("resize", listeningWindow);
onBeforeUnmount(() => {
	window.removeEventListener("resize", listeningWindow);
});
</script>

<style scoped lang="scss">
@import "./index.scss";
</style>
